let mysql = require('mysql');

//创建数据库连接
let pool = mysql.createPool({
    host:'localhost',
    port:3306,
    user:'root',
    password:'root',
    database:'test',
    insecureAuth:true
});

function getCon(){
    return new Promise((resolve,reject)=>{
        pool.getConnection((err,con)=>{
            if(err){
                reject(err);
            }else{
                resolve(con);
                
            }
        });
    });

}
async function sqlQuery(sql,pms){
    let con = await getCon();
    return new Promise((resolve,reject)=>{
        con.query(sql,pms,(err,data)=>{
            if(err){
                reject(err);
            }else{
                resolve(data);
                con.release();
            }
        });
    });

}
module.exports = sqlQuery;